//力扣234. 回文链表
 class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }

class Solution {
    public boolean isPalindrome(ListNode head) {
        //计算长度
        int len = 0;
        ListNode cur = head;
        while(cur!=null){
            cur = cur.next;
            len++;
        }
        //根据长度创建数组
        int[] arr = new int[len];
        cur = head;
        int k = 0;
        while(cur!=null){
            arr[k++]=cur.val;
            cur = cur.next;
        }
        //使用双指针
        int l = 0;
        int r = len-1;
        while(r>l){
            if(arr[l++]!=arr[r--]){
                return false;
            }
        }
        return true;
    }
}